package refactor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import common.standard.table.OrganizationFieldEnum;
import common.standard.table.PageEnum;
import org.springframework.beans.factory.annotation.Autowired;
import refactor.entity.Organization;
import refactor.mapper.OrganizationMapper;
import refactor.service.IOrganizationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用于记录使用此系统的用户所属于的单位 服务实现类
 * </p>
 *
 * @author 杨健
 * @since 2019-08-19
 */
@Service
public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper, Organization> implements IOrganizationService {
    private OrganizationMapper organizationMapper;

    @Autowired
    public void setOrganizationMapper(OrganizationMapper organizationMapper) {
        this.organizationMapper = organizationMapper;
    }


    /**
     * 根据regionId和status分页查询
     *
     * @param regionId 区域id
     * @param pageNum 当前页码
     * @return 返回分页包装对象
     */
    @Override
    public IPage<Organization> pageList(Integer regionId, Integer pageNum) {
		QueryWrapper<Organization> organizationQueryWrapper = new QueryWrapper<>();
		organizationQueryWrapper.eq(OrganizationFieldEnum.REGION_ID.getFieldName(), regionId)
				.eq(OrganizationFieldEnum.STATUS.getFieldName(), "");

		Page<Organization> organizationPage = new Page<>(pageNum, PageEnum.PAGE_SIZE.getValue());
        return organizationMapper.selectPage(organizationPage, organizationQueryWrapper);
    }
}
